/**
 * 角色管理相关常量定义
 */

// 角色状态枚举
export enum RoleStatus {
  NORMAL = "0",
  DISABLED = "1"
}

// 角色状态选项
export const ROLE_STATUS_OPTIONS = [
  { label: "正常", value: RoleStatus.NORMAL, type: "success" },
  { label: "停用", value: RoleStatus.DISABLED, type: "danger" }
];

// 角色状态映射
export const ROLE_STATUS_MAP = {
  [RoleStatus.NORMAL]: { text: "正常", type: "success" },
  [RoleStatus.DISABLED]: { text: "停用", type: "danger" }
};

// 系统角色列表
export const SYSTEM_ROLES = ["admin", "system"];

// 角色标识验证规则
export const ROLE_KEY_RULES = {
  minLength: 2,
  maxLength: 50,
  pattern: /^[a-zA-Z0-9_]+$/,
  message: "角色标识只能包含字母、数字和下划线，长度为2-50个字符"
};

// 角色名称验证规则
export const ROLE_NAME_RULES = {
  minLength: 2,
  maxLength: 100,
  message: "角色名称长度为2-100个字符"
};

// 角色描述验证规则
export const ROLE_DESCRIPTION_RULES = {
  maxLength: 500,
  message: "角色描述最多500个字符"
};

// 分页默认配置
export const ROLE_PAGE_CONFIG = {
  defaultPageSize: 10,
  pageSizes: [10, 20, 50, 100],
  layout: "total, sizes, prev, pager, next, jumper"
};

// 表格列配置
export const ROLE_TABLE_COLUMNS = [
  { prop: "id", label: "ID", width: 80 },
  { prop: "roleKey", label: "角色标识", width: 150 },
  { prop: "roleName", label: "角色名称", width: 150 },
  {
    prop: "description",
    label: "描述",
    minWidth: 200,
    showOverflowTooltip: true
  },
  { prop: "status", label: "状态", width: 100 },
  { prop: "userCount", label: "用户数量", width: 100 },
  { prop: "createTime", label: "创建时间", width: 180 }
];

// 搜索表单默认值
export const ROLE_SEARCH_FORM_DEFAULT = {
  roleKey: "",
  roleName: "",
  status: ""
};

// 角色表单默认值
export const ROLE_FORM_DEFAULT = {
  roleKey: "",
  roleName: "",
  description: "",
  status: RoleStatus.NORMAL,
  permissionIds: []
};

// 权限相关常量
export const PERMISSION_CONFIG = {
  maxHeight: 400,
  itemHeight: 60,
  searchPlaceholder: "搜索权限..."
};

// 操作按钮配置
export const ROLE_ACTION_BUTTONS = {
  add: { text: "新增角色", type: "primary", icon: "ep:plus" },
  edit: { text: "编辑", type: "primary", size: "small" },
  permission: { text: "权限", type: "info", size: "small" },
  delete: { text: "删除", type: "danger", size: "small" },
  batchDelete: { text: "批量删除", type: "danger", icon: "ep:delete" }
};

// 消息提示文本
export const ROLE_MESSAGES = {
  createSuccess: "角色创建成功",
  createFailed: "角色创建失败",
  updateSuccess: "角色更新成功",
  updateFailed: "角色更新失败",
  deleteSuccess: "角色删除成功",
  deleteFailed: "角色删除失败",
  batchDeleteSuccess: "角色批量删除成功",
  batchDeleteFailed: "角色批量删除失败",
  statusUpdateSuccess: "角色状态更新成功",
  statusUpdateFailed: "角色状态更新失败",
  permissionAssignSuccess: "权限分配成功",
  permissionAssignFailed: "权限分配失败",
  permissionRemoveSuccess: "权限移除成功",
  permissionRemoveFailed: "权限移除失败",
  loadListFailed: "获取角色列表失败",
  loadPermissionsFailed: "获取权限列表失败",
  roleKeyExists: "角色标识已存在",
  roleKeyValidateFailed: "验证角色标识失败",
  cannotDeleteRole: "该角色不能删除",
  selectRolesToDelete: "请选择要删除的角色",
  confirmDelete: '确定要删除角色"{name}"吗？此操作不可恢复！',
  confirmBatchDelete: "确定要删除选中的 {count} 个角色吗？此操作不可恢复！",
  confirmStatusChange: '确定要{action}角色"{name}"吗？',
  confirmRemoveAllPermissions: '确定要移除角色"{name}"的所有权限吗？',
  resetPermissions: "已重置为原始权限"
};

// 对话框配置
export const ROLE_DIALOG_CONFIG = {
  edit: {
    width: "800px",
    title: {
      add: "新增角色",
      edit: "编辑角色"
    }
  },
  permission: {
    width: "1000px",
    title: "管理角色权限"
  }
};

// 表单验证配置
export const ROLE_FORM_RULES = {
  roleKey: [
    { required: true, message: "请输入角色标识", trigger: "blur" },
    {
      min: ROLE_KEY_RULES.minLength,
      max: ROLE_KEY_RULES.maxLength,
      message: `角色标识长度为${ROLE_KEY_RULES.minLength}-${ROLE_KEY_RULES.maxLength}个字符`,
      trigger: "blur"
    },
    {
      pattern: ROLE_KEY_RULES.pattern,
      message: ROLE_KEY_RULES.message,
      trigger: "blur"
    }
  ],
  roleName: [
    { required: true, message: "请输入角色名称", trigger: "blur" },
    {
      min: ROLE_NAME_RULES.minLength,
      max: ROLE_NAME_RULES.maxLength,
      message: ROLE_NAME_RULES.message,
      trigger: "blur"
    }
  ],
  description: [
    {
      max: ROLE_DESCRIPTION_RULES.maxLength,
      message: ROLE_DESCRIPTION_RULES.message,
      trigger: "blur"
    }
  ],
  status: [{ required: true, message: "请选择状态", trigger: "change" }]
};

// 导出所有常量
export default {
  RoleStatus,
  ROLE_STATUS_OPTIONS,
  ROLE_STATUS_MAP,
  SYSTEM_ROLES,
  ROLE_KEY_RULES,
  ROLE_NAME_RULES,
  ROLE_DESCRIPTION_RULES,
  ROLE_PAGE_CONFIG,
  ROLE_TABLE_COLUMNS,
  ROLE_SEARCH_FORM_DEFAULT,
  ROLE_FORM_DEFAULT,
  PERMISSION_CONFIG,
  ROLE_ACTION_BUTTONS,
  ROLE_MESSAGES,
  ROLE_DIALOG_CONFIG,
  ROLE_FORM_RULES
};
